﻿using System;
using Plugins.Core.Interfaces;

namespace Plugins.Core
{
    [Serializable]
    public class PluginExecuteConnector<T> : PluginConnector<T>, IPluginExecuteConnector<T>, IPluginConnector<T>
    {
        protected virtual bool CanExecute(T obj) { return !object.Equals(Object, default(T)); }
        protected virtual bool ExecuteConnector(T obj)
        {
            if (!CanExecute(obj))
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        public bool Execute(Action<T> action)
        {
            lock (this)
            {
                if (ExecuteConnector(Object))
                {
                    action(Object);
                    return true;
                }
                return false;
            }
        }
    }
}
